﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace yf倒计时
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            label1.Text = trackBar1.Value.ToString()+"分钟";
        }
        int formHeig;//窗体初始宽度
        private void Form3_Load(object sender, EventArgs e)
        {
            button1.Text = "开始计时";
           formHeig= this.Height;//保留初始宽度用于恢复显示进度条。
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(t1<=0)
            {
                timer1.Stop();
                trackBar1.Visible = true;
                button1.Text = "开始";
                label1.Visible = true;
                this.Height = formHeig;
                label3_X.Visible = true;
            
                Form2 fm2 = new Form2();
                fm2.Show();
            }
            else
            {

                t1 = t1 - 0.1;//每100ms减去0.1秒
                double t = t1 / t2 * progressBar1.Maximum; //百分比换算成进度条值；         
                progressBar1.Value = Convert.ToInt32(t);
                label2.Text = Convert.ToInt32(t1).ToString()+"秒";
            }
        }

        double t1 ;
        double t2;
        private void button1_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled)
            {
                timer1.Stop();
                trackBar1.Visible = true;
                button1.Text = "开始计时";
                label1.Visible = true;
                progressBar1.Value = 0;
                label2.Text = progressBar1.Value+ "秒";
                this.Height = formHeig;

            }
            else
            {
                t1 = trackBar1.Value*60;//变化秒
                t2 = trackBar1.Value * 60;//初始秒
                timer1.Start();
                trackBar1.Visible = false;
                button1.Text = "终止计时";
                label1.Visible = false;
                label3_X.Visible = false;
                this.Height = progressBar1.Height;


            }
        }

        private void progressBar1_Click(object sender, EventArgs e)
        {
            if (this.Height == formHeig) {
                label3_X.Visible = false;
                this.Height = progressBar1.Height;
            }
            else
            {
                label3_X.Visible = true;
                this.Height = formHeig;
               
            }

        }

        private void label3_X_Click(object sender, EventArgs e)
        {
            
            this.Close();
        }

        private void Form3_AutoSizeChanged(object sender, EventArgs e)
        {
            Console.WriteLine("尺寸变化");
            if (this.Height == formHeig)
            {
                label3_X.Visible = false;
                this.Height = progressBar1.Height;
            }
            else
            {
                label3_X.Visible = true;
                this.Height = formHeig;

            }
        }

        private void label3_X_VisibleChanged(object sender, EventArgs e)
        {
            //////纠错
            ////if (this.Height == formHeig)
            ////{
            ////    label3_X.Visible = true;
            ////}
            ////else {
            ////    label3_X.Visible = false;

            ////}
        }
    }
}
